package com.yuyue.springFramework.note11.entity.springCode;

import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;

/**
 * 用户注册服务
 */
@Component
public class UserRegisterService4 implements ApplicationEventPublisherAware {
    //事件发布器
    private ApplicationEventPublisher applicationEventPublisher;

    //@Autowired
    @Override
    public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
        this.applicationEventPublisher = applicationEventPublisher;
    }

    //注册用户方法
    public void registerUser(String name){
        System.out.println(String.format("【%S】用户注册成功", name));

        //发布发送邮件事件
        applicationEventPublisher.publishEvent(new UserRegisterEvent(this, name));
    }
}
